(ns picture-gallery.handler
  (:require
            [compojure.core :refer [defroutes routes]]
    ; [hiccup.middleware :refer [wrap-base-url]]
    ;       [compojure.handler :as handler]
            [compojure.route :as route]

            [picture-gallery.routes.home :refer [home-routes]]
            [picture_gallery.routes.auth :refer [auth-routes]]
            [picture_gallery.routes.upload :refer [upload-routes]]
            [picture_gallery.routes.gallery :refer [gallery-routes]]

            [noir.session :as session]
    ;       [noir.util.route :refer :all]
            [noir.util.middleware :as noir-middleware]
            ;[ring.middleware.session.memory
            ; :refer [memory-store]]
            ;[noir.validation
            ; :refer [wrap-noir-validation]]
            ))

(defn init []
  (println "picture-gallery is starting"))

(defn destroy []
  (println "picture-gallery is shutting down"))

(defroutes app-routes
  (route/resources "/")
  (route/not-found "Not Found"))

(defn user-page [_]
  (session/get :user))

;(def app
;  (-> (routes
;        auth-routes
;        upload-routes
;        home-routes app-routes
;        )
;      (handler/site)
;      (session/wrap-noir-session
;        {:store (memory-store)})
;      (wrap-noir-validation)
;      (wrap-base-url)))



(def app
  (noir-middleware/app-handler
    [home-routes
     upload-routes
     auth-routes
     gallery-routes
     app-routes]
    :access-rules [user-page]))

